-
Notifications
You must be signed in to change notification settings - Fork 79
Add a client/service demo for typescript #1195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a comprehensive TypeScript demo for rclnodejs, demonstrating how to create ROS2 service servers and clients using TypeScript. The demo includes a complete project structure with proper TypeScript configuration, build scripts, and detailed documentation.
Key changes:
- Adds a complete TypeScript service demo with client and server implementations
- Implements AddTwoInts service with proper type handling and error management
- Updates main README to include reference to the new TypeScript demo
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ts_demo/services/tsconfig.json | TypeScript compiler configuration with strict settings and proper output structure |
| ts_demo/services/src/server.ts | Service server implementation that provides AddTwoInts service with logging and error handling |
| ts_demo/services/src/client.ts | Service client implementation that calls AddTwoInts service at regular intervals |
| ts_demo/services/package.json | Package configuration with build scripts, dependencies, and development tools |
| ts_demo/services/README.md | Comprehensive documentation with usage instructions, examples, and troubleshooting |
| README.md | Updated main README to reference the new TypeScript demo |
| const service = node.createService( | ||
| 'example_interfaces/srv/AddTwoInts', | ||
| SERVICE_NAME, | ||
| (request: any, response: any) => { |
Copilot
AI
Jul 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'any' type defeats the purpose of TypeScript's type safety. Consider defining proper interfaces for the request and response types or using the appropriate rclnodejs types.
| (request: any, response: any) => { | |
| (request: AddTwoIntsRequest, response: AddTwoIntsResponse) => { |
| console.log(` Timestamp: ${new Date().toISOString()}`); | ||
|
|
||
| // Send the request and wait for response | ||
| client.sendRequest(request, (response: any) => { |
Copilot
AI
Jul 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'any' type for response parameter removes type safety benefits. Consider defining proper interface for the AddTwoInts response type.
| client.sendRequest(request, (response: any) => { | |
| client.sendRequest(request, (response: AddTwoIntsResponse) => { |
| import * as rclnodejs from 'rclnodejs'; | ||
|
|
||
| const SERVICE_NAME = 'add_two_ints'; | ||
| const REQUEST_INTERVAL = 3000000000n; // 3 seconds in nanoseconds |
Copilot
AI
Jul 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The magic number 3000000000n is not immediately clear. Consider defining a constant with a more descriptive calculation like 3 * 1000 * 1000 * 1000 or using a conversion function.
| const REQUEST_INTERVAL = 3000000000n; // 3 seconds in nanoseconds | |
| const REQUEST_INTERVAL = 3n * 1000n * 1000n * 1000n; // 3 seconds in nanoseconds |
This PR adds a comprehensive TypeScript demo for rclnodejs, demonstrating how to create ROS2 service servers and clients using TypeScript. The demo includes a complete project structure with proper TypeScript configuration, build scripts, and detailed documentation. Key changes: - Adds a complete TypeScript service demo with client and server implementations - Implements AddTwoInts service with proper type handling and error management - Updates main README to include reference to the new TypeScript demo Fix: #1193
This PR adds a comprehensive TypeScript demo for rclnodejs, demonstrating how to create ROS2 service servers and clients using TypeScript. The demo includes a complete project structure with proper TypeScript configuration, build scripts, and detailed documentation.
Key changes:
Fix: #1193